package com.huitone.smspfm.redis;

import java.util.Iterator;

import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * 
* @Title: BaseAbstractDao.java 
* @Package com.huitone.smspfm.redis 
* @Description: TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年3月15日 上午10:29:45 
* @version V1.0
 */
public abstract class BaseAbstractOpts<K, V> {
	
	public RedisTemplate<K, V> redisTemplate;
	
	public IRedisInit configInit;
	
	public Integer numCnt;
	
	

	public Integer getNumCnt() {
		return numCnt;
	}

	public void setNumCnt(Integer numCnt) {
		this.numCnt = numCnt;
	}

	public IRedisInit getConfigInit() {
		return configInit;
	}

	public void setConfigInit(IRedisInit configInit) {
		this.configInit = configInit;
	}

	public RedisTemplate<K, V> getRedisTemplate() {
		return redisTemplate;
	}

	public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}
	
	public RedisSerializer<String> getRedisSerializer() {
		return redisTemplate.getStringSerializer();
	}
	
	public String getMasterAddressPort() {
		
		String masterAddressPort = "";
		
		try {
			
			Iterator<RedisServer> iterator = redisTemplate.getConnectionFactory().getSentinelConnection().masters().iterator();
			if (iterator.hasNext()) {
				RedisServer redisServer = iterator.next();
				masterAddressPort = redisServer.getHost() + "/" + redisServer.getPort();
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return masterAddressPort;
	}
	
	
}
